package cac.fenjian.resource.mswptoolbasic.api;
import cac.fenjian.resource.MsWorkbinBasic.dto.MsWorkbinBasicDTO;
import cac.fenjian.resource.MsWpTool.dto.MsWpToolBasicDTO;
import cac.fenjian.resource.common.InvokeService;
import cac.fenjian.resource.common.RestUtil;
import com.cac.dme.adapter.rest.client.RestClient;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.QueryRespBean;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.cac.dme.adapter.utils.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/MsToolApi")
public class MsWpToolBasicApi {
    /**
     * 服务编码
     */
    private static final String SERVICE_CODE="xdCommonData";
    private static final String BASE_PATH = "/MsWpTool";

    @Autowired
    private RestClient restClient;

    @Autowired
    private InvokeService invokeService;

    @Autowired
    private RestUtil restUtil;

    /**
     * 按条件分页查询api
     * @param queryReqBean
     * @return
     */
    @PostMapping("/searchByPage")
    public String searchByPage(@RequestBody QueryReqBean<MsWorkbinBasicDTO> queryReqBean ){
        String url = BASE_PATH +"/searchByPage/v1";
        restUtil.setRestClient(restClient);
        String result = restUtil.callServicePost(url, SERVICE_CODE, queryReqBean, new ParameterizedTypeReference<String>() {
        });
        return  result;
    }

    /**
     * 根据条件查询数据
     * @param queryReqBean
     * @return
     */
    @PostMapping("/searchByParams")
    public List<MsWpToolBasicDTO> searchMsToolByParams(@RequestBody QueryReqBean<MsWpToolBasicDTO> queryReqBean){
        String url = BASE_PATH + "/searchByParams/v1";
        restUtil.setRestClient(restClient);
        ResponseMsg<List<MsWpToolBasicDTO>> responseMsg = restUtil.callServicePost(url, SERVICE_CODE, queryReqBean, new ParameterizedTypeReference<ResponseMsg<List<MsWpToolBasicDTO>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg) ;
    }

    @PostMapping("/searchByParamsRest")
    public QueryRespBean<MsWpToolBasicDTO> searchByParamsRest(@RequestBody QueryRespBean<MsWpToolBasicDTO> queryRespBean){
        String url = BASE_PATH + "/searchByParams/v1";
        ResponseMsg<QueryRespBean<MsWpToolBasicDTO>> responseMsg = restUtil.callServicePost(url, SERVICE_CODE, queryRespBean, new ParameterizedTypeReference<ResponseMsg<QueryRespBean<MsWpToolBasicDTO>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 新增功能API
     * @param msWpToolBasicDTO
     * @return
     */
    @PostMapping("/insertMsTool")
    public String insertMsTool(@RequestBody MsWpToolBasicDTO msWpToolBasicDTO){
        String url = BASE_PATH +"/save/v1";
        String result = invokeService.callServicePost(url,SERVICE_CODE,msWpToolBasicDTO);
        return result;
    }

    /**
     * 批量新增API
     * @param msWpToolBasicDTOList
     * @return
     */
    @PostMapping("/insertManyMsTool")
    public String insertMsToolMany(@RequestBody List<MsWpToolBasicDTO> msWpToolBasicDTOList){
        String url = BASE_PATH +"/saveMany/v1";
        String result = restUtil.callServicePost(url, SERVICE_CODE, msWpToolBasicDTOList, new ParameterizedTypeReference<String>() {
        });
        return result;
    }

    /**
     * 删除API
     * @param id
     * @return
     */
    @PostMapping("/deleteMsTool")
    public String deleteMsTool(@RequestBody String id){
        String url = BASE_PATH+"/deleteById/v1";
//        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, id, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
//        });
        String result = invokeService.callServicePost(url,SERVICE_CODE,id);
//        return RestClientUtils.getResponseBody(responseMsg);
        return result;
    }

    /**
     * 批量删除apI
     * @param id
     * @return
     */
    @PostMapping("/deleteManyMsTool")
    public String deleteManyMsTool(@RequestBody String[] id){
        String url = BASE_PATH+"/deleteMany/v1";
        String result = invokeService.callServicePost(url,SERVICE_CODE,id);
        return result;
    }


    /**
     * 更新数据
     * @param msWpToolBasicDTO
     * @return
     */
    @PostMapping("/updateMsTool")
    public String updateMsTool(@RequestBody MsWpToolBasicDTO msWpToolBasicDTO){
        String url = BASE_PATH+"/update/v1";
        String result = invokeService.callServicePost(url,SERVICE_CODE,msWpToolBasicDTO);
        return result;
    }

    /**
     * 批量更新数据
     * @param msWpToolBasicDTOS
     * @return
     */
    @PostMapping("/updateMsToolMany")
    public String updateMsToolMany(@RequestBody List<MsWpToolBasicDTO> msWpToolBasicDTOS){
        String url = BASE_PATH + "/updateMany/v1";
        String result = invokeService.callServicePost(url,SERVICE_CODE,msWpToolBasicDTOS);
        return result;
    }
}
